package com.symc.sims0213xfw.dao.impl;

import com.symc.sims0213xfw.bean.StudentView;
import com.symc.sims0213xfw.dao.StudentViewDao;
import com.symc.sims0213xfw.utils.JDBCUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import java.sql.SQLException;
import java.util.List;

/**
 * @Author: 凤文  沈阳医学院2019级医学信息工程 0213
 * @CreateTime: 2022/01/22 20:14
 * @Description:
 */
public class StudentViewDaoImpl implements StudentViewDao {
    private static QueryRunner qr = new QueryRunner(JDBCUtils.getDataSource());

    @Override
    public List<StudentView> queryListStudentView() {
        List<StudentView> studentViews = null;
        try {
            studentViews = qr.query("select * from studentView",
                    new BeanListHandler<StudentView>(StudentView.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return studentViews;
    }

    @Override
    public List<StudentView> queryListVisibleStudentView() {
        List<StudentView> studentViews = null;
        try {
            studentViews = qr.query("select * from studentView where " +
                            "isVisible=1",
                    new BeanListHandler<StudentView>(StudentView.class));
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return studentViews;
    }

    @Override
    public List<StudentView> queryListStudentView(String param) {
        return null;
    }

    @Override
    public StudentView queryStudentView(String id) {
        String sql = "select * from studentView where id= ?";
        StudentView studentView = null;
        try {
            studentView = qr.query(sql, new BeanHandler<StudentView>(StudentView.class)
                            , id);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }
        return studentView;
    }
}
